<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Edit Event's Agenda</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="../assets/css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="http://localhost:8000/static/bootstrap.css" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../assets/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  <script type="text/javascript">
  //This block is a Javascript used to validate the time format the user enters //
  $().ready(function() {

	    $.validator.addMethod("time", function(value, element) {  
	    return this.optional(element) || /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(value);  
	    },"Please enter a valid time in the format HH:MM.");

	        $("#input").validate({
	                rules: {
	                        time: "required time",
	                },

	        });
			$("#EditForm").validate({
		                rules: {
		                        time: "required time",
		                },
		
		        });

	    });
    
  $(document).ready(function(){
			$('#agenda').validate();
			$('#ActivityForm').validate();
			$('#ActivityForm2').validate();
			
			$('#EditForm').validate();
			$('#addFields').validate();
			$('#input').validate();
		});	
  

</script>
<!-- This block is a Javascript used to identify whether or not a user selected a certain activity to edit or not. Accordingly certain forms will show and hide -->
		<script type="text/javascript">
			var st = ${{template.startTime}} + ""
			var counter = 0
			function checkSelected(id) 
			{		
						alert( st );
					counter=1;
					$('#edit').hide();
					$('#addFields').hide();
				    $('#editFields').show(1000);
					
			}
			<!-- This function is called as the user deletes a certain activity so as as to conform the user's request-->
			function check() 
			{
					var r = confirm ("Are you sure you want to delete the activity ?")
					if (r == false)
					{
						return false;
					}
					else 
					{
						EditForm.action = '/deleteActivity/';
					}
					
			}
			<!-- This block consists of 2 functions that are called as the user edits a certain activity -->
			function save(){
			if(counter == 0) 
			{
					$('#edit').show();
					$('#delete').hide();
					
					return false;
				}
				else{
				 return true;
				}
			
			}
			
			
			function done(){
				$('#editFields').hide(1000);							
				$('#addFields').show();
			
			}
			function dateCheck(){
		var start = ($('#Start').val());
		var end = ($('#End').val());
 
	
	 if (start > end || start==end)
 {
	$('#timeError').show();
		return false;
 }
	else
	{
		$('#timeError').hide();
		return true;
	}
	
}
	function dateCheck2(){
		var start = ($('#StartTime').val());
	
	var end = ($('#EndTime').val());
 
	
	 if (start > end || start==end)
 {
	$('#time').show();
		return false;
 }
	else
	{
		$('#time').hide();
		return true;
	}
	
}
</script>
</head>

 <body>

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <ul class="nav">

          <a class="brand" href="/homePage/">Eventati</a>
          <li><a href ="/DashboardHome/">Home Page</a></li>      
          <li > <a href="/AboutUs/">About Us</a></li>
          <li><a href="/ViewInstructions/">Instructions</a></li>
          <li><a href  ="/Terms&Conditions/">  Terms & Conditions</a></li>
         <li><a href  ="/News/">  Latest News and Updates</a></li>
         <li><a href ="/Faqs/"> FAQS</a></li>
         <li><a href ="/Contactus/"> Contactus</a></li>
		<!-- Author: Amina Kadry This form is for logging the user out of his account -->
         <li><a href="/logout/" method="POST">Log out</a></li>
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container">
      <!-- Main hero unit for a primary marketing message or call to action -->
      		<h1>Edit Event's Agenda</h1>
      
      <div class="hero-unit">
<ul>

<!-- This conditon is used to control the visibility of the table of activities; as the table would only appear if the agenda has at least one activity -->
      
	  {% if Activities %}
<!-- This block represents the formation of the table which will include all the agenda's activities -->
	  
   		<form id = "Edit" name="EditForm" action="/editEventActivity/" onclick="return dateCheck();" method="POST"> 
 <TABLE id="Agenda" width="500px" border="1" align="center">
<thead>
        <tr>
        	<th></th>
            <th> Edit </th>           
   			<th> Time</th>
   			<th> Description</th>
  		</tr>
</thead>
<tfoot>
  		{% for A in Activities %}
			  <tr>
			  <TD> <input type="image" name="delete" , value = "{{ A.id }}" src="http://icons.iconarchive.com/icons/deleket/sleek-xp-basic/16/Close-2-icon.png" onclick = "return check();"</TD>
			  <TD><INPUT type="radio" name="activity" , value = "{{ A.id }}" onclick = "checkSelected('{{ A.id }}')">
			  <TD> <OUTPUT type = "time" name = "time" /> {{ A.startTime }} - {{  A.endTime }} </TD>
			  <TD>  <OUTPUT type = "text" /> {{ A.description }} </TD>
			  </tr>
		 {% endfor %}
</tfoor>
      </TABLE>
      
<       <div id="editFields" style="display:none;"><h3> Edit activity :</h3> 
        Description : <input  id = "textID" type="text" size="20" name="textID" value="{{text}}"  class = "required" /></br>
  Start Time:<input id="Start" name="StartTime"  value="00:00" type="time" class = "required"/><br />
  End Time:<input id="End" name="EndTime" input value="00:00" type="time" size="18" class = "required"/><br />
 <div id="timeError" style="display:none;">  End time and start time are not valid</font> </div>
	  <!-- This is the error message that appears if the user doesnt select a certain activity to edit -->	  	
 	  <div id="edit" style="display:none;"> <font face="Comic Sans MS" color="red"> You haven't checked any activity to be edited </font></div>
 	  
	  <!-- The submit buttons related to editing an activity-->	  	
	  <INPUT type="image"  name = "edit" src="http://icons.iconarchive.com/icons/jackietran/rounded/24/Done-icon.png " onclick = "return save();"/><br />
 	  <INPUT type="button"  name = "edit" value="Cancel Editing" onclick = "return done();"/><br />
 	  
 	   </div>
 	   
 	  		{%if wrongEditTime%}
 	  		<script>
 	  		editCheck() 
 	  		</script>
			<p> <font color = "RED">Kindly enter valid times that match the event's timings</font></p>
		{% endif %}
		
		
 	  </form>
 	   	  	  <!-- This form is called as the user creates a certain activity ,inwhich the user enter new inputs -->
 	  
          <div id="addFields" ><h3>

    <h3> Add an activity :</h3> 
   		
<form name="ActivityForm2" id="input"  action="/addEventActivity/"  onclick= "return dateCheck2();" method="POST">
  Description : <input  id = "textID" type="text" size="20" name="textID"   class = "required" /></br>
  Start Time:<input id="StartTime" name="StartTime"  value="00:00" type="time" class = "required"/><br />
  End Time:<input id="EndTime" name="EndTime" input value="00:00" type="time" size="18" class = "required"/><br />
 <div id="time" style="display:none;">  End time and start time are not valid</font> </div>
 
  <INPUT type="submit" value="Add Activity"  />  
  </div>
  </form>
	{%if wrongTime%}
		 	  		<script>
 	  		editCheck() 
 	  		</script>
			<p> <font color = "RED">Kindly enter valid times that match the event's timings</font></p>
		{% endif %}

		{% else %}

	 	  <div id="Empty"> <font color="red"><h3> You haven't added any activities to your Agenda </font></h3></div>
	 	          <div id="addFields" >

    <h3> Add an activity :</h3> 
   		
<form name="ActivityForm" id="input"  action="/addEventActivity/"  onclick="return dateCheck();" method="POST">
  Description : <input  id = "textID" type="text" size="20" name="textID"   class = "required" /></br>
  Start Time:<input id="Start" name="StartTime"  value="00:00" type="time" class = "required"/><br />
  End Time:<input id="End" name="EndTime" input value="00:00" type="time" size="18" class = "required"/><br />
<div id="timeError" style="display:none;">  End time and start time are not valid</font> </div>
 
  <INPUT type="submit" value="Add Activity" />  
  </div>
  </form>
	{% endif %}
<form action="/eventPage/" method="POST">
{% csrf_token %}
<input type = "submit" name="submit" value = "submit"/>
<br>
</form>
      </div>
      </div>   
      </div>

      <hr>

      <footer>
      <p class="pull-center">
		 <a href="/AboutUs/">About Us</a>
				<a href="/ViewInstructions/">Instructions</a>
				<a href  ="/Terms&Conditions/">  Terms & Conditions</a>
				<a href  ="/News/">  Latest News and Updates</a>
				<a href ="/Faqs/"> FAQS</a>
				<a href ="/Contactus/"> Contactus</a>
				<p class="pull-right"><a href="#">Back to top</a></p>

				        <p>&copy; Company 2012</p>      </footer>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../assets/js/jquery.js"></script>
    <script src="../assets/js/bootstrap-transition.js"></script>
    <script src="../assets/js/bootstrap-alert.js"></script>
    <script src="../assets/js/bootstrap-modal.js"></script>
    <script src="../assets/js/bootstrap-dropdown.js"></script>
    <script src="../assets/js/bootstrap-scrollspy.js"></script>
    <script src="../assets/js/bootstrap-tab.js"></script>
    <script src="../assets/js/bootstrap-tooltip.js"></script>
    <script src="../assets/js/bootstrap-popover.js"></script>
    <script src="../assets/js/bootstrap-button.js"></script>
    <script src="../assets/js/bootstrap-collapse.js"></script>
    <script src="../assets/js/bootstrap-carousel.js"></script>
    <script src="../assets/js/bootstrap-typeahead.js"></script>

  </body>
</html>